package fr.afcepf.atod12.projet1.managedbeans;

import java.util.ArrayList;
import java.util.List;

import javax.faces.component.UIParameter;
import javax.faces.model.SelectItem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import fr.afcepf.atod12.projet1.entities.Evenement;
import fr.afcepf.atod12.projet1.entities.Medecin;
import fr.afcepf.atod12.projet1.entities.Patient;
import fr.afcepf.atod12.projet1.entities.TypeEvenement;
import fr.afcepf.atod12.projet1.facades.IFacadeServices;


@Controller("mbRdv")
@Scope("session")
public class RdvBean {

	@Autowired
	@Qualifier("facadeService")
	private IFacadeServices facade;
	private List<SelectItem> listTypeEvenement = new ArrayList<SelectItem>();
	private UIParameter idMedecin;
	private Medecin medecin;
	private String typeEvenement;
	private String nomPatient;
	private String prenomPatient;
	private String dateRdv;
	private List<Patient> listPatientAuto = new ArrayList<Patient>();
	private String saisiePatient;
	
	
	public String redirectRdv(){
		medecin = facade.getServicePersonne().getMedecinById(Integer.parseInt(idMedecin.getValue().toString()));
		return "ajoutRdv";
	}
	
	public String recherchePatient(){
		
		return "";
	}
	
	public String validerRdv(){
		return "";
	}
	
	public List<String> autocompletePatient(Object suggest) {

		String pref = (String) suggest;
		List<String> result = new ArrayList<String>();
		for(Patient patient: facade.getServicePersonne().getPatientByName(pref)){
				result.add(patient.getNom());
		}
		return result;

	}
	
	public final List<SelectItem> getListTypeEvenement() {
		listTypeEvenement = new ArrayList<SelectItem>();
		listTypeEvenement.add(new SelectItem("---------"));
		for (TypeEvenement te : facade.getServiceEvenement().getAllTypeEvenement()) {
			listTypeEvenement.add(new SelectItem(te.getLibelleTypeEvenement().toString()));
		}
		return listTypeEvenement;
	}
	
	
	public final void setListTypeEvenement(List<SelectItem> listTypeEvenement) {
		this.listTypeEvenement = listTypeEvenement;
	}

	public final Medecin getMedecin() {
		return medecin;
	}

	public final void setMedecin(Medecin medecin) {
		this.medecin = medecin;
	}

	public final void setIdMedecin(UIParameter idMedecin) {
		this.idMedecin = idMedecin;
	}

	public final UIParameter getIdMedecin() {
		return idMedecin;
	}

	public final String getTypeEvenement() {
		return typeEvenement;
	}

	public final void setTypeEvenement(String typeEvenement) {
		this.typeEvenement = typeEvenement;
	}

	public final String getNomPatient() {
		return nomPatient;
	}

	public final void setNomPatient(String nomPatient) {
		this.nomPatient = nomPatient;
	}

	public final String getPrenomPatient() {
		return prenomPatient;
	}

	public final void setPrenomPatient(String prenomPatient) {
		this.prenomPatient = prenomPatient;
	}

	public final String getDateRdv() {
		return dateRdv;
	}

	public final void setDateRdv(String dateRdv) {
		this.dateRdv = dateRdv;
	}

	public final List<Patient> getListPatientAuto() {
		return listPatientAuto;
	}

	public final void setListPatientAuto(List<Patient> listPatientAuto) {
		this.listPatientAuto = listPatientAuto;
	}

	public final String getSaisiePatient() {
		return saisiePatient;
	}

	public final void setSaisiePatient(String saisiePatient) {
		this.saisiePatient = saisiePatient;
	}
}
